#include "stdafx.h"
#include "PicOpts.h"


PicOpts::PicOpts()
{
}


PicOpts::~PicOpts()
{
}

void PicOpts::cbitMapToImage(CImage *image, CBitmap *bitmap)
{
	HBITMAP hbitmap = HBITMAP(bitmap->GetSafeHandle());
	image->Attach(hbitmap);
}

void PicOpts::imageToCbitMap(CBitmap *bitmap, CImage *image)
{
	HBITMAP hBitmap = image->Detach();
	bitmap->Attach(hBitmap);
}

void PicOpts::CopyBitmap(CBitmap *src, CBitmap *dest)
{
	BITMAP srcInfo;

	src->GetBitmap(&srcInfo);

	BYTE imgSize = srcInfo.bmBitsPixel / 8;
	BYTE* lpvBits = new BYTE[srcInfo.bmWidth * srcInfo.bmHeight * imgSize];


	long sizeofdata = srcBitMap.GetBitmapBits(srcInfo.bmWidth * srcInfo.bmHeight * imgSize, lpvBits);

	if (0 == sizeofdata)
	{
		delete[] lpvBits;
		lpvBits = NULL;
	}
	
	destBitMap.SetBitmapBits(srcInfo.bmWidth * srcInfo.bmHeight * imgSize, lpvBits);

	if (lpvBits != NULL)
	{
		delete[] lpvBits;
		lpvBits = 0;
	}
}

void PicOpts::clearRect(CDC* pDC, int width, int height)
{
	CRect rc(0, 0, width, height);
	pDC->FillSolidRect(&rc, RGB(255, 255, 255));
}